import 'package:flutter/material.dart';
import 'package:flutter_soundmagus/util/util.dart';
export './underline_button.dart';
export './group_link_button.dart';

class ZFButton extends StatelessWidget {
  final String title;
  final bool selected;
  final void Function()? onLongPress;
  final void Function()? onPressed;
  final void Function()? onDoubleTap;
  final Widget? icon;
  final TextStyle? style;
  final Size? size;
  final Color? borderColor;
  final Color? selectedBackgroundColor;
  final bool enable;
  const ZFButton(
      {Key? key,
      required this.title,
      this.selected = false,
      this.enable = true,
      this.onPressed,
      this.onLongPress,
      this.onDoubleTap,
      this.icon,
      this.size,
      this.borderColor = Colors.white,
      this.selectedBackgroundColor,
      this.style})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final color = selected ? Theme.of(context).primaryColor : Colors.white;
    final decoration = BoxDecoration(
        color: selected ? selectedBackgroundColor : null,
        border: Border.all(color: borderColor ?? Colors.white),
        borderRadius: BorderRadius.all(Radius.circular(3)));
    final text = Text(
      title,
      style: style != null
          ? style!.apply(color: color)
          : TextStyle(color: color, fontSize: 12),
    );
    Widget child = GestureDetector(
      onDoubleTap: onDoubleTap,
      onLongPress: onLongPress,
      onTap: onPressed,
      child: Container(
          decoration: decoration,
          width: size?.width ?? 42.w,
          height: size?.height ?? 22.w,
          alignment: Alignment.center,
          child: icon != null
              ? Row(
                  children: [text, icon!],
                )
              : text),
    );
    return IgnorePointer(
      child: child,
      ignoring: !enable,
    );
  }
}

class ZFImageButton extends StatelessWidget {
  final String image;
  final double? width;
  final bool selected;
  final void Function()? onTap;

  ZFImageButton(this.image, {this.selected = false, this.onTap, this.width});
  @override
  Widget build(BuildContext context) {
    var src = (selected ? '${image}_s' : image);
    Widget child = width != null ? src.uiimgw(width!) : src.uiimg;
    if (onTap == null) {
      return child;
    }
    return GestureDetector(
      child: child,
      onTap: onTap,
    );
  }
}

typedef ImgBtn = ZFImageButton;
